<template>
  <view class="container">
		<nav-ber :title="'激活流程'" :bgColor="'#f7f8ff'"></nav-ber>
		<view class="province">
			<u-steps  :current="current" direction="column">
				<u-steps-item title="第一步: 个人信息审核">
					<view slot="desc">
						<view style="margin: 20rpx 0;display: inline-block;overflow: hidden;">
							<u-tag size="mini" style="display: inline-block;" :text="(status >= 2 && status !=3)? '已完成': (status == 1? '已提交' : (status == 3? '已驳回' : '未完成'))" :type="(status >= 2 && status != 3)? 'success' : 'warning'" plain plainFill></u-tag>
						</view>
						<view class="dis_flex">
							<view style="flex:1">
								需提交个人身份证正反面、学历证书、从业年限、服务范围、医院、专长领域等信息审核。
							</view>
							<view style="margin-left: 20rpx;">
								<u-button v-if="status==3 || status==0" @click="personFun" type="primary" text="去认证"></u-button>
								<u-button v-else type="primary" @click="personFun('1')" text="查看"></u-button>
							</view>
						</view>
					</view>
				</u-steps-item>
				<u-steps-item title="第二步: 学习视频">
					<view slot="desc">
						<view style="margin: 20rpx 0;display: inline-block;overflow: hidden;">
							<u-tag size="mini" style="display: inline-block;" :text="status >= 4? '已完成': '未完成'" :type="status >= 4?'success':'warning'" plain plainFill></u-tag>
						</view>
						<view class="dis_flex">
							<view style="flex:1">
								需学习满5个产品视频。
							</view>
							<view style="margin-left: 20rpx;">
								<u-button v-if="status == 2" @click="styFun" type="primary" text="去完成"></u-button>
								<u-button v-if="status >= 4" type="primary" disabled text="完成"></u-button>
								<u-button v-if="status < 2 || status == 3" disabled type="primary" text="去完成"></u-button>
							</view>
						</view>
					</view>
				</u-steps-item>
				<u-steps-item title="第三步: 完成试卷">
					<view slot="desc">
						<view style="margin: 20rpx 0;display: inline-block;overflow: hidden;">
							<u-tag size="mini" style="display: inline-block;" :text="status>=5? '已完成':'未完成'" :type="status>=5?'success':'warning'" plain plainFill></u-tag>
						</view>
						<view class="dis_flex">
							<view style="flex:1">
								需完成试卷成绩不低于90分，不通过需重新考试。
							</view>
							<view style="margin-left: 20rpx;">
								<u-button v-if="status>=5" disabled type="primary" text="完成"></u-button>
								<u-button v-if="status == 4" @click="mytastFun" type="primary" text="去完成"></u-button>
								<u-button v-if="status < 4" disabled type="primary" text="去完成"></u-button>
							</view>
						</view>
					</view>
				</u-steps-item>
				<u-steps-item title="第四步: 签订协议">
					<view slot="desc">
						<view style="margin: 20rpx 0;display: inline-block;overflow: hidden;">
							<u-tag size="mini" style="display: inline-block;" :text="status == 6? '已完成' : (status == 8? '已驳回': (status == 7?'已提交':'未完成'))" :type="status == 6? 'success' : 'warning'" plain plainFill></u-tag>
						</view>
						<view class="dis_flex">
							<view style="flex:1">
								医药代表需完成服务协议在线签订，包括《代表协议》、《反腐承诺书》、《推广行为准则》。
							</view>
							<view style="margin-left: 20rpx;">
								<u-button v-if="status == 6" type="primary" disabled text="完成"></u-button>
								<u-button v-else-if="status == 5 || status == 8" @click="myAgreemenFun" type="primary" text="提交"></u-button>
								<u-button v-else  type="primary" disabled text="提交"></u-button>
							</view>
						</view>
						<view>
							<view :style="(status == 5 || status == 8)? '':'pointer-events:none'">
								<uFrom ref="getFrom" :itemList="itemList" :itemKeys.sync="itemKeys" @changeFun="changeFun"></uFrom>
							</view>
							<view :style="(status == 5 || status == 8)? '':'pointer-events:none'">
								<uFrom ref="getFrom" :itemList="itemList1" :itemKeys.sync="itemKeys1" @changeFun="changeFun1"></uFrom>
							</view>
							<view :style="(status == 5 || status == 8)? '':'pointer-events:none'">
								<uFrom ref="getFrom" :itemList="itemList2" :itemKeys.sync="itemKeys2" @changeFun="changeFun2"></uFrom>
							</view>
						</view>
					</view>
				</u-steps-item>
			</u-steps>
		</view>
  </view>
</template>
<script>
	import { listByMr, addAgreement } from '@/api/personalCenter.js'
	import { getbyuser, medicalRepresentative } from "@/api/login/index.js"
	import { itemList, itemList1, itemList2 } from './items.js'
  export default {
    data() {
			return {
				listAgree: [],
				agreementListNew: [],
				itemList: itemList,
				itemList1: itemList1,
				itemList2: itemList2,
				itemKeys: {
					fileList: [],
					photoList: [],
					urlFil: '',
					documentList: []
				},
				itemKeys1: {
					fileList: [],
					photoList: [],
					urlFil: '',
					documentList: []
				},
				itemKeys2: {
					fileList: [],
					photoList: [],
					urlFil: '',
					documentList: []
				},
				keyword: '',
				ispro: '1',
				bottonisShow: true,
				status: null,
				Id: '',
				current: 0,
			}
    },
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
				uni.removeStorageSync("singImg");
				this.listByMrFun()
				if(option.type == 1){
					this.bottonisShow = false
				}
				// ((JSON.parse(uni.getStorageSync('userInfo')).userType == '02')? medicalRepresentative : getbyuser)(JSON.parse(uni.getStorageSync('userInfo')).userId).then((resmin) => {
				// 	this.status = resmin.data.status
				// 	if(this.status>2 && this.status != 3) {
				// 		this.current = 0
				// 	} 
				// 	if(this.status>=4) {
				// 		this.current = 1
				// 	} 
				// 	if(this.status>=5) {
				// 		this.current = 2
				// 	} 
				// 	if (this.status==6) {
				// 		this.current = 3
				// 	}
				// 	if (this.status==7 || this.status==8) {
				// 		this.current = 2
				// 	}
				// 	this.Id = resmin.data.id
				// })
//打印出上个页面传递的参数。传递的是id=1，则获取到的就是option.id
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				
				((JSON.parse(uni.getStorageSync('userInfo')).userType == '02')? medicalRepresentative : getbyuser)(JSON.parse(uni.getStorageSync('userInfo')).userId).then((resmin) => {
					// console.log('resmin', resmin.data.)
					// this.itemKeys.urlFil = resmin.data.agreementList[0].mrSignedUrl
					// this.itemKeys1.urlFil = resmin.data.agreementList[1].mrSignedUrl
					// this.itemKeys2.urlFil = resmin.data.agreementList[2].mrSignedUrl
					// this.itemKeys.documentList = resmin.data.agreementList[0]
					// this.itemKeys.urlFil = resmin.data.agreementList[0]?.mrSignedUrl
					this.itemKeys.documentList = [{
						name: resmin.data.agreementList.filter(item => item.type == 1)[0]?.name,
						url: resmin.data.agreementList.filter(item => item.type == 1)[0]?.url,
					}]
					console.log('我进来啦1122')
					this.itemKeys.urlFil = resmin.data.agreementList.filter(item => item.type == 1)[0]?.url
					this.agreementListNew[0] = {
						name: resmin.data.agreementList.filter(item => item.type == 1)[0]?.name,
						url: resmin.data.agreementList.filter(item => item.type == 1)[0]?.url,
						type: 1
					}
					
					this.itemKeys1.documentList = [{
						name: resmin.data.agreementList.filter(item => item.type == 2)[0]?.name,
						url: resmin.data.agreementList.filter(item => item.type == 2)[0]?.url
					}]
					this.itemKeys1.urlFil = resmin.data.agreementList.filter(item => item.type == 2)[0]?.url
					this.agreementListNew[1] = {
						name: resmin.data.agreementList.filter(item => item.type == 2)[0]?.name,
						url: resmin.data.agreementList.filter(item => item.type == 2)[0]?.url,
						type: 2
					}
					this.itemKeys2.documentList = [{
						name: resmin.data.agreementList.filter(item => item.type == 3)[0]?.name,
						url: resmin.data.agreementList.filter(item => item.type == 3)[0]?.url,
					}]
					this.itemKeys2.urlFil = resmin.data.agreementList.filter(item => item.type == 3)[0]?.url
					this.agreementListNew[2] = {
						name: resmin.data.agreementList.filter(item => item.type == 3)[0]?.name,
						url: resmin.data.agreementList.filter(item => item.type == 3)[0]?.url,
						type: 3
					}
					this.status = resmin.data.status
					if(this.status == 0) {
						this.current = 0
					} 
					if(this.status>2 && this.status != 3 && this.status != 0) {
						this.current = 1
					} 
					if(this.status>=4) {
						this.current = 2
					} 
					if(this.status>=5) {
						this.current = 3
					} 
					if (this.status==6) {
						this.current = 4
					}
					if (this.status==7 || this.status==8) {
						this.current = 3
					}
					this.Id = resmin.data.id
				})
			},
			listByMrFun() {
				listByMr(false).then((res) => {
					this.listAgree = res.rows
				})
			},
			changeFun(val) {
				console.log('11223', val)
				this.agreementListNew[0] = val.agreementList[0]
				this.agreementListNew[0].type = 1
				
				console.log('fsad24123', this.agreementListNew)
			},
			changeFun1(val) {
				console.log('11223', val)
				this.agreementListNew[1] = val.agreementList[0]
				this.agreementListNew[1].type = 2
				console.log('fsad241236677', this.agreementListNew)
			},
			changeFun2(val) {
				console.log('11223', val)
				this.agreementListNew[2] = val.agreementList[0]
				this.agreementListNew[2].type = 3
				console.log('fsad241236677y54586', this.agreementListNew)
			},
			myAgreemenFun() {
				console.log('this.itemKeys', this.agreementListNew)
				let agreementList = []
				if (this.agreementListNew.length == 3) {
					// this.listAgree.forEach((item, index) => {
					// 	agreementList.push({
					// 		agreementId: item.id,
					// 		agreementName: item.name,
					// 		// mrSignedUrl: this.datas[index].url
					// 	})
					// })
					agreementList = this.agreementListNew
					// agreementList[0].url = this.itemKeys.urlFil
					// agreementList[0].name = this.itemKeys.documentList[0].name
					// agreementList[0].type = 1
					// agreementList[1].url = this.itemKeys1.urlFil
					// agreementList[1].name = this.itemKeys1.documentList[0].name
					// agreementList[1].type = 2
					// agreementList[2].url = this.itemKeys2.urlFil
					// agreementList[2].name = this.itemKeys2.documentList[0].name
					// agreementList[2].type = 3
					addAgreement({
						agreementList,
						id: this.Id,
						load: false
					}).then((res) => {
						// this.showTimefilter = true
						this.init()
						uni.showToast({
						  title: '提交成功',
						  icon: "none",
						  duration: 2000,
						})
					})
				} else {
					uni.showToast({
					  title: '请先上传协议',
					  icon: "none",
					  duration: 2000,
					})
				}
				// uni.navigateTo({
				// 	url: "/pages/personalCenter/myAgreement/index?id=" + this.Id
				// })
			},
			mytastFun() {
				uni.navigateTo({
					url: "/pages/mytaskManagement/questionPaperAnswers/index"
				})
			},
			styFun() {
				uni.navigateTo({
					url: "/pages/task/studyArea/index"
				})
			},
			personFun(type) {
				uni.navigateTo({
					url: "/pages/personalCenter/personalAudit/index?id=" + this.Id + (type == 1?'&check="1"' : '')
				})
			},
			gotoStamenFun() {
				uni.navigateTo({
					url: "/pages/personalCenter/statementDetails/index"
				})
			},
			proFun(val) {
				this.ispro = val
			}
		}
  }
</script>
<style lang="scss" scoped>
	.container {
		background-color: #f7f8ff;
		display: flex;
		flex-direction: column;
		height: 100vh;
		overflow: hidden;
	}
	.province {
		flex: 1;
		overflow: scroll;
		padding: 0 20rpx;
		margin-top: 20rpx;
	}
	.dis_flex {
		display: flex;
		align-items: flex-start;
	}
</style>
